/*
 * @Author: C.
 * @Date: 2023-03-14 10:03:06
 */
import { unref } from 'vue';
import { useTabs } from '/@/hooks/web/useTabs';
import { useRouter, RouteLocationRaw, Router } from 'vue-router';
interface IAppRouter {
  closeTo(to: RouteLocationRaw): void;
}

export function useAppRouter(): ReturnType<typeof useTabs> & IAppRouter & Router {
  const router = useRouter();
  const tabs = useTabs(router);
  function closeTo(to: RouteLocationRaw): void {
    tabs.close(unref(router.currentRoute));
    router.push(to);
  }
  return {
    closeTo,
    ...router,
    ...tabs,
  };
}
